home *** CD-ROM | disk | FTP | other *** search
- Integer force1, force2, planet1Con, planet2Con, planet3Con;
- Real VectorX, VectorY, DistanceX, DistanceY, XFactor, YFactor;
- Real Distance, Gee, force;
- real XArray[4], YArray[4];
-
- real me[], planet1[], planet2[], planet3[];
-
- ** Planet block
- ** Copyright © 1993 by Imagine That, Inc.
- ** All rights reserved.
- ** J. Steven Lamperti 3/10/93
- ** modified
- **
-
- // planet array elements
- //
- // me[0] = mass;
- // me[1] = x;
- // me[2] = y;
- // me[3] = planetID;
- // me[4] = density;
-
-
- integer planetID()
- {
- if (earth)
- return(1);
- else if (mars)
- return(2);
- else if (venus)
- return(3);
- else if (moon)
- return(4);
- else if (sun)
- return(5);
-
- return(4);
- }
-
-
- Procedure calc()
- {
- if (Distance < Mass/Density)
- {
- userError("Interplanetary Collision! Block:"+(myBlockNumber()+1)+".");
- Abort;
- }
-
- if (DistanceX != 0.0)
- {
- Xfactor = (DistanceY^2)/(DistanceX^2)+1.0;
- Xfactor = (Gee^2) / Xfactor;
- Xfactor = sqrt(Xfactor);
- if (DistanceX>0.0)
- Xfactor = -Xfactor;
- }
-
- if (DistanceY != 0.0)
- {
- Yfactor = (DistanceX^2)/(DistanceY^2)+1.0;
- Yfactor = (Gee^2) / Yfactor;
- Yfactor = sqrt(Yfactor);
- if (DistanceY>0.0)
- Yfactor = -Yfactor;
- }
- }
-
-
- ** This message occurs for each step in the simulation.
-
- on simulate
- {
- if ( CurrentStep !=0)
- {
- VectorX = 0.0;
- VectorY = 0.0;
- if (planet1Con)
- {
- GetPassedArray(planet1In, planet1);
- DistanceX = (me[1]-planet1[1]);
- DistanceY = (me[2]-planet1[2]);
- Distance = sqrt(DistanceX^2+DistanceY^2);
- Force = planet1[0]/(Distance^2);
- Gee = Force/Mass;
- Calc();
- VectorX = XFactor;
- VectorY = YFactor;
- }
-
- if (planet2Con)
- {
- GetPassedArray(planet2In, planet2);
- DistanceX = (me[1]-planet2[1]);
- DistanceY = (me[2]-planet2[2]);
- Distance = sqrt(DistanceX^2+DistanceY^2);
- Force = planet2[0]/(Distance^2);
- Gee = Force/Mass;
- Calc();
- VectorX += XFactor;
- VectorY += YFactor;
- }
-
- if (planet3Con)
- {
- GetPassedArray(planet3In, planet3);
- DistanceX = (me[1]-planet3[1]);
- DistanceY = (me[2]-planet3[2]);
- Distance = sqrt(DistanceX^2+DistanceY^2);
- Force = planet3[0]/(Distance^2);
- Gee = Force/Mass;
- Calc();
- VectorX += XFactor;
- VectorY += YFactor;
- }
-
- me[1] += IntegrateEuler(Xarray, VectorX, DeltaTime)*DeltaTime;
- me[2] += IntegrateEuler(Yarray, VectorY, DeltaTime)*DeltaTime;
- }
-
- meOut = passArray(me);
- }
-
-
-
- ** If the dialog data is inconsistent for simulation, abort.
- on checkdata
- {
- if (Mass == 0.0 || NoValue(Mass))
- {
- userError("Mass is missing, or zero.");
- Abort;
- }
-
- if (Density == 0.0 || NoValue(Density))
- {
- userError("Density is missing, or zero.");
- Abort;
- }
-
- if (NoValue(StartX) || NoValue(StartY))
- {
- userError("You must input starting Coordinates.");
- Abort;
- }
-
- planet1Con = planet1In;
- planet2Con = planet2In;
- planet3Con = planet3In;
-
- makeArray(me, 5);
- }
-
-
-
- ** Initialize any simulation variables.
- on initsim
- {
- if (NoValue(DeltaX)) DeltaX = 0.0;
- if (NoValue(DeltaY)) DeltaY = 0.0;
-
- VectorX = 0.0;
- VectorY = 0.0;
-
- XFactor = 0.0;
- YFactor = 0.0;
-
- DistanceX = 0.0;
- DistanceY = 0.0;
-
- Distance = 0.0;
-
- IntegrateInit(Xarray, DeltaX);
- IntegrateInit(Yarray, DeltaY);
-
- me[0] = mass;
- me[1] = startX;
- me[2] = startY;
- me[3] = planetID();
- me[4] = Density;
- }
-
-
- on createBlock
- {
- makeArray(me, 5);
-
- AnimationPicture(1, "Moon", TRUE);
- AnimationShow(1);
-
- density = 1;
- mass = 5;
- startX = 0;
- startY = 0;
- deltaX = 0;
- deltaY = 0;
- moon = 1;
-
- me[0] = mass;
- me[1] = startX;
- me[2] = startY;
- me[3] = planetID();
- me[4] = Density;
- }
-
-
- on DialogClose
- {
- makeArray(me, 5);
-
- me[0] = mass;
- me[1] = startX;
- me[2] = startY;
- me[3] = planetID();
- me[4] = Density;
-
- if (moon)
- AnimationPicture(1, "Moon", TRUE);
- else if (sun)
- AnimationPicture(1, "Sun", TRUE);
- else if (earth)
- AnimationPicture(1, "Earth", TRUE);
- else if (mars)
- AnimationPicture(1, "Mars", TRUE);
- else if (venus)
- AnimationPicture(1, "Venus", TRUE);
- else
- AnimationPicture(1, "Moon", TRUE);
-
- AnimationShow(1);
- }